package com.esri.core.tasks.na;

import com.esri.core.internal.util.d;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public class NetworkDescription {
    private String mNetworkName;
    private List<CostAttribute> mCostAttributes = new ArrayList();
    private List<RestrictionAttribute> mRestrictionAttributes = new ArrayList();
    List<String> mSupportedDirectionsLanguages = new ArrayList();
    List<String> mSupportedDirectionsStyles = new ArrayList();
    private String mDefaultLanguage = null;
    String mDefaultDirectionsTimeAttribute = null;
    String mDefaultImpedance = null;
    List<String> mDefaultAccumulates = new ArrayList();

    private NetworkDescription() {
    }

    public String getName() {
        return this.mNetworkName;
    }

    public List<CostAttribute> getCostAttributes() {
        return this.mCostAttributes;
    }

    public List<RestrictionAttribute> getRestrictionAttributes() {
        return this.mRestrictionAttributes;
    }

    public List<String> getSupportedDirectionsLanguages() {
        return this.mSupportedDirectionsLanguages.isEmpty() ? Arrays.asList(this.mDefaultLanguage) : this.mSupportedDirectionsLanguages;
    }

    public List<String> getSupportedDirectionsStyles() {
        return this.mSupportedDirectionsStyles;
    }

    public static List<String> getRestrictionUsageParameterValues() {
        return Arrays.asList("Prohibited", "Avoid_High", "Avoid_Medium", "Avoid_Low", "Prefer_Low", "Prefer_Medium", "Prefer_High");
    }

    public static NetworkDescription fromJson(JsonParser jsonParser) throws Exception {
        if (d.c(jsonParser)) {
            HashMap hashMap = new HashMap();
            NetworkDescription networkDescription = new NetworkDescription();
            while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                String currentName = jsonParser.getCurrentName();
                jsonParser.nextToken();
                if ("networkDataset".equals(currentName)) {
                    if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) {
                        break;
                    }
                    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                        String currentName2 = jsonParser.getCurrentName();
                        jsonParser.nextToken();
                        if ("name".equals(currentName2)) {
                            networkDescription.mNetworkName = jsonParser.getText();
                        } else if ("networkAttributes".equals(currentName2) && jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                            while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                                ArrayList arrayList = new ArrayList();
                                String str = null;
                                String str2 = null;
                                String str3 = null;
                                AttributeUnits attributeUnits = null;
                                while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                                    String currentName3 = jsonParser.getCurrentName();
                                    jsonParser.nextToken();
                                    if ("name".equals(currentName3)) {
                                        str2 = jsonParser.getText();
                                    } else if ("usageType".equals(currentName3)) {
                                        str = jsonParser.getText();
                                    } else if ("units".equals(currentName3)) {
                                        attributeUnits = AttributeUnits.fromString(jsonParser.getText());
                                    } else if ("restrictionUsageParameterName".equals(currentName3)) {
                                        str3 = jsonParser.getText();
                                    } else if ("parameterNames".equals(currentName3) && jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                                        while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                                            String text = jsonParser.getText();
                                            if (text != null) {
                                                Map map = (Map) hashMap.get(str2);
                                                arrayList.add(new AttributeParameter(text, map == null ? null : (String) map.get(text)));
                                            }
                                        }
                                    }
                                }
                                if ("esriNAUTCost".equals(str)) {
                                    if (str2 == null || str2.isEmpty()) {
                                        throw new NetworkAnalystException("Service not supported");
                                    }
                                    networkDescription.mCostAttributes.add(new CostAttribute(str2, attributeUnits, arrayList));
                                } else if ("esriNAUTRestriction".equals(str)) {
                                    networkDescription.mRestrictionAttributes.add(new RestrictionAttribute(str2, str3, arrayList));
                                }
                            }
                            continue;
                        } else {
                            jsonParser.skipChildren();
                        }
                    }
                    continue;
                } else if ("attributeParameterValues".equals(currentName) && jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                        AttributeParameterValue fromJson = AttributeParameterValue.fromJson(jsonParser);
                        if (!hashMap.containsKey(fromJson.getAttributeName())) {
                            hashMap.put(fromJson.getAttributeName(), new HashMap());
                        }
                        ((Map) hashMap.get(fromJson.getAttributeName())).put(fromJson.getParameterName(), fromJson.getValue());
                    }
                } else if ("directionsSupportedLanguages".equals(currentName) && jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                        String text2 = jsonParser.getText();
                        if (text2 != null) {
                            networkDescription.mSupportedDirectionsLanguages.add(text2);
                        }
                    }
                } else if ("directionsStyleNames".equals(currentName) && jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                        String text3 = jsonParser.getText();
                        if (text3 != null) {
                            networkDescription.mSupportedDirectionsStyles.add(text3);
                        }
                    }
                } else if ("accumulateAttributeNames".equals(currentName) && jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                        String text4 = jsonParser.getText();
                        if (text4 != null) {
                            networkDescription.mDefaultAccumulates.add(text4);
                        }
                    }
                } else if ("impedance".equals(currentName) && jsonParser.getCurrentToken() != JsonToken.VALUE_NULL) {
                    networkDescription.mDefaultImpedance = jsonParser.getText();
                } else if ("directionsTimeAttribute".equals(currentName) && jsonParser.getCurrentToken() != JsonToken.VALUE_NULL) {
                    networkDescription.mDefaultDirectionsTimeAttribute = jsonParser.getText();
                } else if ("directionsLanguage".equals(currentName) && jsonParser.getCurrentToken() != JsonToken.VALUE_NULL) {
                    networkDescription.mDefaultLanguage = jsonParser.getText();
                } else {
                    jsonParser.skipChildren();
                }
            }
            return networkDescription;
        }
        return null;
    }
}
